package demo3;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Text04 {
    public static void main(String[] args) throws InterruptedException {
        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(3,
                5, 1, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(5),
                new ThreadPoolExecutor.DiscardOldestPolicy());
        // 通过循环向线程池中添加任务
        for (int i = 0; i < 100; i++) {
            int taskId = i + 1;
            threadPool.submit(() -> {
                System.out.println("执行任务 : " + taskId + ", " +  Thread.currentThread().getName());
            });
        }
    }
}
